//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#if !defined (_POWER_H_)
#define _POWER_H_

class CPower : public Driver {
public:
    CARAPI Read(
        /* [in] */ UINT64 u64Offset,
        /* [in] */ UINT uNumberOfBytesToRead,
        /* [out] */ EzByteBuf ebbData,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ UINT64 u64Offset,
        /* [in] */ EzByteBuf ebbData,
        /* [out] */ UINT * puNumberOfBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ INT nControlCode,
        /* [in] */ EzByteBuf ebbInData,
        /* [out] */ EzByteBuf ebbOutData,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose(){}
    void EnableAutoSleepTest(BOOL AutoTest);

};

#define 	VOLT_MIN	0x0
#define 	VOLT_LOW	0x1
#define	VOLT_HIGH	0x2
#define	VOLT_MAX	0x3
#define CLK_SRAM 0x00100000

#ifdef  __cplusplus
extern "C" {
#endif

void pxa_cpu_suspend(void);
int get_cpu_mode();
void pxa_cpu_resume(void);
EXTERN_C Address GetSP(void);
EXTERN_C ULONG save_flags_cli();
EXTERN_C void restore_flags(ULONG);
#define BASE_FREQ   13000000
EXTERN_C Address sleep_save_sp;
unsigned long current_freq;
EXTERN_C void WritePWRMODE(int);
EXTERN_C void WriteCLKCFG(int);

/*for auto sleep test*/
ECode PowerCreateTimer(int *pTimerID,unsigned long Resolution,unsigned  Interval,TimerCallBackProc pCallbackProc,void * pvArg);
ECode PowerKillTimer(int TimerID);
ECode PowerStartTimer(int TimerID);
ECode PowerStopTimer(int TimerID);
ECode PowerReStartTimer(int TimerID,int Interval);
ECode PowerSetTimerInterval(int TimerID, int Interval);

#define RTSR        __REG(0x40900008)
#define PIAR        __REG(0x40900038)
#define RTCPICR     __REG(0x40900034)
#define RCNR        __REG(0x40900000)

#ifdef  __cplusplus
}
#endif
#define SAVE(x)     sleep_save[SLEEP_SAVE_##x] = x
#define RESTORE(x)  x = sleep_save[SLEEP_SAVE_##x]
#define _HAL_EnterCritical(s)   (s = 1)
#define _HAL_LeaveCritical(s)   (s = 0)
#endif //_POWER_H_
